package fr.epsi.planning;

import android.content.Context;
import android.database.Cursor;
import fr.epsi.BDD.BDD;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Florent Baudon on 26/05/2014.
 */
public class ConvertiseurTaches {

    public static List<Tache> recupererTaches(Context c){
        BDD bdd = new BDD();
        Cursor cListInfos;
        List<Tache> taches = new ArrayList<Tache>();
        try {
            bdd.open(c);

        } catch (SQLException e) {
            e.printStackTrace();
        }
        cListInfos = bdd.getTaches();

        if(cListInfos!=null && cListInfos.moveToFirst()){
            while(!cListInfos.isAfterLast()) {
                String label = cListInfos.getString(1);
                String service = cListInfos.getString(2);
                String date = cListInfos.getString(5).substring(0, 10);
                String heureDebut = cListInfos.getString(5).substring(11, 15);
                String heureFin = cListInfos.getString(6).substring(11, cListInfos.getString(6).length());

                taches.add(new Tache(date, heureDebut, heureFin, service, label));

                cListInfos.moveToNext();
            }
        }

        return taches;
    }

}
